// pages/sale/sale/sale.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    navbarData: {
      havebg: 0, //1表示不显示    0表示显示
      out: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '选择售后类型', //导航栏 中间的标题
      bg: '#fff', //导航背景
    },
    height: app.globalData.height,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    let goods = wx.getStorageSync('goods')
    goods.forEach((item) => {
      item.check = false
    })
    // goods.push({
    //   asale_status: 0,
    //   good_id: 156,
    //   good_name: "产品2",
    //   id: 13903,
    //   image: "https://zyq.tjhaiqing.com/upload/e2/9c54016517dc66a5d92bc72392ca5e.jpg",
    //   num: 6,
    //   order_id: 8778,
    //   price: "12.00",
    // })
    _this.setData({
      goods: goods,
      price: wx.getStorageSync('price'),
    })
  },
  //选择售后类型
  onText(e) {
    console.log(e)
    let asale_type = this.data.asale_type
    let list = this.data.goods
    let price = 0
    let goods = []
    if (!asale_type) {
      wx.showToast({
        title: "请选择售后类型",
        icon: 'none',
        duration: 2000
      })
      return
    }
    list.forEach((item) => {
      if (item.check) {
        goods.push(item)
        price += item.price * item.num
      }
    })
    if (goods.length == 0) {
      wx.showToast({
        title: "请选择售后商品",
        icon: 'none',
        duration: 2000
      })
      return
    }
    wx.setStorageSync('goods', goods);
    wx.setStorageSync('price', price);
    wx.redirectTo({
      url: '/pages/sale/afterRefund/afterRefund?asale_type=' + asale_type,
    })
  },
  onasTyple(e) {
    this.setData({
      asale_type: e.currentTarget.dataset.asale_type
    })
  },
  ongoodsCheck(e) {
    let dataset = e.currentTarget.dataset
    let goods = this.data.goods
    goods[dataset.index].check = dataset.check ? false : true
    this.setData({
      goods
    })
  },
  scroll: function (e) {
    // console.log(e)
    this.setData({
      scrollTop: e.detail.scrollTop
    });
    if (e.detail.scrollTop >= 40) {
      this.setData({
        headerBg: true
      })
    } else {
      this.setData({
        headerBg: false
      })
    }
  },
  //返回上一页
  out() {
    wx.navigateBack({
      delta: 1,
    })
  },


})